/* e_subgroup.do -  ***********************************************************

	Joint p-values for tests where the null hypothesis is effects are equal
	across subgroups. Appears in Table 8 (subgroup analysis)

******************************************************************************/
set more off

local specs "an_fr_K1 an_fr_K1_cntrl an_fr_K1_fem"
use "$stata_data_analysis/final_sample.dta", clear

gen male = female == 0

local outcome_list any_6m_asgn any4yr_nsc_6m grad_4yr_ontime_asgn_4yr ///
	grad_ontime_asgn any4yr_nsc_6m_asgn everany_nsc everany4yr_nsc ////
	any_nsc everany_nsc_4yr evergrad_nsc has_sat_took_10 grad_hs ///
	hs_ever_anysusp hs_ever_incarcerated behav_index_tot num_sem grad_or_enrolled_nsc

matrix pval = J(60,6,.)
local i = 1
preserve
keep if !inlist(pformELC, 0,1) | !inlist(pformnLC, 0,1)
matrix list pval
restore

group_p_score, endogvars(att) instruments(soffany) idvar(studentno) ///
	group_var(not_frpl frpl) pscores(pformany) outcomes(`outcome_list')  ///
	outfile("$results/tables/frpl_not") restriction("in_K1 & !inlist(pformany,0,1)")

group_p_score, endogvars(att) instruments(soffany) idvar(studentno) ///
	group_var(black white hispanic) pscores(pformany) outcomes(`outcome_list') ///
	outfile("$results/tables/bwh") restriction("in_K1 & !inlist(pformany,0,1)")

group_p_score, endogvars(att) instruments(soffany) idvar(studentno) ///
	group_var(male female) pscores(pformany) outcomes(`outcome_list') ///
	outfile("$results/tables/male_fem") restriction("in_K1 & !inlist(pformany,0,1)")

keep studentno att in_sims in_K1 soffany yr_asgn male female hispanic asian female black white share_white share_black ///
share_hispanic med_inc_hh med_gross_rent pop std_scaled_e3-std_scaled_e8 ///
std_scaled_e10 std_scaled_m4-std_scaled_m8 std_scaled_m10 nLC ELC soff* pform* ///
behav_index* frpl not_frpl inc1 inc2 inc3 inc4

reshape long std_scaled_e std_scaled_m behav_index, i(studentno) j(grade)

group_p_score, endogvars(att) instruments(soffany) idvar(studentno) ///
	group_var(black white hispanic) pscores(pformany) outcomes(std_scaled_e std_scaled_m) ///
	outfile("$results/tables/test_bwh") restriction("in_K1 & !inlist(pformany,0,1)") cluster(studentno)

group_p_score, endogvars(att) instruments(soffany) idvar(studentno) ///
	group_var(male female) pscores(pformany) outcomes(std_scaled_e std_scaled_m) ///
	outfile("$results/tables/test_male_fem") restriction("in_K1 & !inlist(pformany,0,1)") cluster(studentno)

group_p_score, endogvars(att) instruments(soffany) idvar(studentno) ///
	group_var(not_frpl frpl) pscores(pformany) outcomes(std_scaled_e std_scaled_m) ///
	outfile("$results/tables/test_frpl_not") restriction("in_K1 & !inlist(pformany,0,1)") cluster(studentno)
